import { createRouter, createWebHistory } from 'vue-router'
import layout from '@/views/Layout/index.vue'
import home from '@/views/Home/index.vue'
import category from '@/views/Category/index.vue'
import secondCategory from '@/views/Category/secondCategory.vue'
import login from '@/views/Login/index.vue'
import userLogin from '@/views/Login/userLogin.vue'
import register from '@/views/Login/userRegister.vue'
import detail from '@/views/Detail/index.vue'
import cart from '@/views/Cart/index.vue'
import pay from '@/views/Pay/index.vue'
import order from '@/views/Order/index.vue'
import member from '@/views/Member/index.vue'
import my from '@/views/Member/my.vue'
import list from '@/views/Member/list.vue'
import paySuccess from '@/views/Pay/paySuccess.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/detail/:id', component: detail },
    {
      path: '/login',
      component: login,
      children: [
        { path: '/login', component: userLogin },
        { path: '/register', component: register }
      ]
    },
    {
      path: '/',
      component: layout,
      children: [
        { path: '/', component: home },
        { path: '/:id', component: category },
        { path: '/category/:id', component: secondCategory },
        { path: '/cart', component: cart },
        { path: '/pay/:id', component: pay },
        { path: '/order', component: order },
        {
          path: '/member',
          component: member,
          redirect: '/my',
          children: [
            { path: '/my', component: my },
            { path: '/list', component: list }
          ]
        },
        { path: '/paySuccess', component: paySuccess }
      ]
    }
  ],
  scrollBehavior() {
    // return 期望滚动到哪个的位置
    return { top: 0 }
  }
})

export default router
